const BehaviorAll = require("../../../behaviors/behavior_all.js");
const GainPhone = require("../../../utils/privacy_gainPhone.js");
const ServiceUser = require("../../../service/service_user.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: {
    editAccountFlag: false,
    account: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      ServiceUser.getAccount(function (data) {
        _this.setData({
          account: data
        });
      });
    },
    /**
     * 关闭编辑框
     */
    onHideEdit: function (e) {
      const _this = this;
      _this.setData({ editAccountFlag: false });
    },
    /**
     * 显示编辑框
     */
    onShowEdit: function(e){
      const _this = this;
      _this.setData({ 
        editAccountFlag: true,
        editType: e.currentTarget.dataset.type
      });
    },
    /**
     * 编辑账户
     */
    onEditAccount: function(e){
      const _this = this;
      const type = e.currentTarget.dataset.type;
      const callback = function (data) {
        _this.setData({ account: data, editAccountFlag: false });
      };
      if (type == 'name'){
        ServiceUser.editAccountName(e.detail.value, callback);
      }else if(type == 'company'){
        ServiceUser.editAccountCompany(e.detail.value, callback);
      } else if (type == 'number') {
        ServiceUser.editAccountNumber(e.detail.value, callback);
      } else if (type == 'bank') {
        ServiceUser.editAccountBank(e.detail.value, callback);
      }
    },
    /**
     * 获取手机号
     */
    onGainPhoneNumber: function(e){
      var _this = this;
      ServiceUser.gainPhone(e, function (data) {
        _this.setData({ account: data });
      });
    }

  }
  
})
